//
//  AppHTTPService.m
//  ApeExample
//
//  Created by Eton on 2017/7/31.
//  Copyright © 2017年 王-庭协. All rights reserved.
//

#import "AppHTTPService.h"
@implementation AppHTTPService

+ (instancetype)shared{
    static AppHTTPService * _shared = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _shared = [[AppHTTPService alloc] initWithBaseURL:@"".tx_URL];
        
    });
    return _shared;
}

- (void)setup{
    [self.manager setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]];
    [self.manager setRequestSerializer:[self apeSerializer]];
    AFHTTPResponseSerializer * response = [self.manager responseSerializer];
    response.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"application/json",@"text/html", nil];
}

- (AFJSONRequestSerializer *)apeSerializer{
    AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
    [requestSerializer setValue:@([NSObject tx_build]).stringValue forHTTPHeaderField:@"version"];
    [requestSerializer setValue:AppSite forHTTPHeaderField:@"site"];
    [requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [requestSerializer setValue:@"ios" forHTTPHeaderField:@"os"];
    [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    return requestSerializer;
}


- (void)setTicket:(NSString *)ticket{
    [self.manager.requestSerializer setValue:ticket forHTTPHeaderField:@"ticket"];
}


@end
